import publicForm from "@/components/public/el-form.vue"; //弹框form
import TableData from "@/components/HntManage/el-tables"; //主页面列表
import formJs from "./regexDetail.js"; //新增弹框配置项
import {
    getWorkLeaderExamineByFid, //查询领导考核页面接口
    saveWorkLeaderExamine, //保存修改
} from "@/api/request.js";
export default {
    props: [
        "dialogVisible",
        "dialogTitle",
        "projectId",
        "status",
        "statusNum",
        "dataFid",
        "currentRow",
        "projectName",
        "fCompanyid",
        "activeIndex"
    ],
    data() {
        return {
            visible: "",
            title: "考核评分",
            isLock: false, // 控制按钮的disable属性\
            btnStatus: [],
            dialogHeight: null,
            // activeIndex: "1",
            formObj: formJs.formObj,
            formObj1: formJs.formObj1,
            formObj2: formJs.formObj2,

            currntData: null,
            dataInfo: null,
            formData: {
                fId: "", //id
                fFillingdates: this.common.getDay(0), //填报时间
                fFillinguserid: "", //填报人id
                fFillingusername: "", //填报人
                fFillingnote: "" //考核说明
            },
            table_config: formJs.table_config,
            tableData: [],
            tableData1: [],
            tableData2: [],

            loading: false,
            formDatafileList: [], //工作计划资料
            btnShow: true,
            startDates: null,
            currentStatus: null,


        };
    },
    components: {
        publicForm,
        TableData
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        projectId: {
            handler(newVal) {
                if (newVal) {
                    console.log(787, newVal);
                    // this.getPerson(newVal);
                }
            },
            immediate: true,
        },
        status: {
            handler(newVal) {
                if (newVal) {
                    this.btnStatus = newVal;
                }
            },
            immediate: true,
        },
        statusNum: {
            handler(newVal) {
                if (newVal) {
                    this.edit(newVal);
                }
            },
            immediate: true,
        },
        dataFid: {
            handler(newVal) {
                if (newVal) {
                    console.log(45, newVal);
                    this.currntData = newVal;

                    this.formData = this.$options.data.call(this).formData;
                    this.getDetail({
                        fId: newVal.fId,
                        // fCompanyid: this.fCompanyid
                    });

                }
            },
            immediate: true,
        },
        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentStatus = newVal;
                }
            },
            immediate: true,
        },
        fCompanyid: {
            handler(newVal) {
                if (newVal) {
                    // this.currentStatus = newVal;
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
        this.btnShow = true
        if (this.statusNum == 1) { //编辑
            this.formData = this.$options.data.call(this).formData;
            this.formObj.map((item) => {
                item.disabled = true;
            });
            this.formObj[9].disabled = false;
            this.formObj[10].disabled = false;
        } else if (this.statusNum == 7) { //查看
            this.btnShow = false
            this.formObj.map((item) => {
                item.disabled = true;
            });
            // this.formObj[6].uploadSelect = false;
            this.formObj1.map((item) => {
                item.disabled = true;
            });
            // this.formObj1[6].uploadSelect = false;
            this.formObj2.map((item) => {
                item.disabled = true;
            });
            // this.formObj2[6].uploadSelect = false;
        }
        this.getHeight();
    },
    methods: {

        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },
        handleSelect(key) {
            this.activeIndex = key;
        },
        closeDialog() {
            this.$emit("close");
        },
        // fCcpeopleData计划传阅人
        selectChange(data, a, b) {
            console.log(data, a, b, this.formData);

        },
        rowChange(val) {
            console.log(val);

        },

        edit(status) {
            if (status == 1) {
                this.formData = this.$options.data.call(this).formData;
            } else if (status == 2) {
                this.formData = this.$options.data.call(this).formData;
            } else if (status == 4) {
                this.monthExamineData = this.$options.data.call(this).monthExamineData;
            }
        },
        // 详情
        getDetail(data1) {
            console.log(79879);
            getWorkLeaderExamineByFid(data1).then((res) => {
                var data = res.data.yjQmpMsWorkleaderexamine;
                this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));

                if (data1.fId != '') {
                    this.formData = data
                    // this.formData1 = data
                    // this.formData2 = data

                    this.tableData = data.workLeaderExaminePageLists
                    this.tableData1 = data.workLeaderFzExaminePageLists
                    this.tableData2 = data.workLeaderJtExaminePageLists

                }

            });
        },


        yj_saveForm() {
            console.log(888, this.formData);
            if (this.statusNum == 1) { //新增

                if (this.$refs.publicForm.submitForm()) {
                    this.saveForm(this.formData);
                } else {
                    console.log("error");
                }
            }
        },

        // 保存
        saveForm(data) {
            // 设置按钮不可点击（disable: false）
            this.isLock = true
            saveWorkLeaderExamine(data)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.isLock = false

                        this.visible = false;
                        this.$emit("refreshList");
                        this.$message.success("编辑成功");
                    } else {
                        this.isLock = false
                        this.$message.error(res.msg);
                        console.log("接口报错");
                    }
                })
                .catch((error) => {
                    console.log("拌合站设置-新增）", error);
                });
        },
    },
};